package net.hn.hnms.biz.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.project.domain.ProjectContent;
import net.hn.hnms.biz.project.request.ProjectContentReq;
import net.hn.hnms.biz.project.service.ProjectContentService;
import net.hn.hnms.biz.project.vo.ProjectContentVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "项目工作项", tags = {"项目工作项"})
@RestController
@RequestMapping("/project/content")
public class ProjectContentController extends BaseController{

    @Autowired
    private ProjectContentService projectContentService;

    /**
     * 新增项目工作项
     */
    @ApiOperation("新增项目工作项")
    @SaCheckPermission("project:content:add")
    @PostMapping("/add")
    @Log(title = "新增项目工作项", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ProjectContentReq projectContentReq) {
        return toAjax(projectContentService.insert(projectContentReq));
    }

    /**
     * 删除项目工作项
     */
    @ApiOperation("删除项目工作项")
    @SaCheckPermission("project:content:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除项目工作项", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        projectContentService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新项目工作项
     */
    @ApiOperation("更新项目工作项")
    @SaCheckPermission("project:content:update")
    @PostMapping("/update")
    @Log(title = "更新项目工作项", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ProjectContentReq projectContentReq) {
        projectContentService.updateById(projectContentReq);
        return R.ok();
    }


    /**
     * 项目工作项详情
     */
    @ApiOperation("项目工作项详情")
    @GetMapping("/{id}")
    public R<ProjectContent> detail(@PathVariable("id") String id) {
        return R.ok(projectContentService.selectDetailById(id));
    }

    /**
     * 项目工作项详情列表
     */
    @ApiOperation("项目工作项列表")
    @GetMapping("/page")
    public R<ResponsePage<ProjectContentVo>> page(ProjectContentReq projectContentReq, PageQuery pageQuery) {
        return R.ok(projectContentService.selectPageList(projectContentReq, pageQuery));
    }




}
